/**
 * 这是关于student表的业务代码
 */
import Model from '../models/student';
import ClassroomModel from '../models/classroom';

export default class Student extends Mod {

  /**
   * 新增学生数据
   */

  @Api({
    // token:true,
    params: {
      studentName: 'string',
      age: 'number',
      sex: 'number?',
      avatarUrl: 'string',
      interests: 'string?',
      classroomId: 'number'
    }
  })
  public async set({
                     studentName, age, sex,
                     avatarUrl, interests, classroomId
                   }: Context) {
    return Model.create({
      name: studentName, age,
      sex, avatarUrl, interests,
      classroomId
    })
  }

  /**
   * 查询案例
   * (通过表内id查询某条具体数据)
   */
  @Api({
    // token:true
    params: {
      studentId: "number"
    }
  })
  public async get({ studentId }: Context) {
    return Model.where({ id: studentId }).findOne()
  }

  /**
   * 查询案例
   * （模糊查询，查询多条）
   */
  @Api({
    // token:true,
    params: {
      studentName: 'string',
    }
  })
  public async getList({ studentName }: Context) {
    return Model.where({
      name: [Op.Lk,
        `%${studentName}%`]
    }).findAll()
  }
}